import { defineComponent, reactive, getCurrentInstance, onMounted, toRefs, computed } from 'vue'
import { useStore } from 'vuex'

export default {
    //时间格式
    dateTime(value,index){
        if(value && value !== '0' && value != '86430'){
            var date = new Date(value*1000) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-'
            var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
            var D = date.getDate() < 10 ? '0'+date.getDate() : date.getDate() 
            if(index == 1){
                var h = ' '+(date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':'
                var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':'
                var s = date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds()
                return Y+M+D+h+m+s
            }else if(index == 2){
                return Y+(date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1)
            }else{
                return Y+M+D
            }
        }else{
            return ''
        }
    },

    //数据字典格式转换
    formatData(value,index){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll).value;
            for(let key in convertData){
                if(index == key){
                    let array = convertData[key];
                    for (let index = 0; index < array.length; index++) {
                        if(value == array[index].name){
                            return array[index].value;
                        }
                    }
                }
            }
        }
    },

    //跟进阶段
    followStage(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.follow_stage).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //业务类型
    businessType(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.business_type).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //信息来源
    infoSource(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.info_source).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //跟进方式
    followMethod(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.follow_method).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //案件类型
    caseType(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.caseType).value;
            for (let index in convertData) {
                if(value == convertData[index].value){
                    return convertData[index].label
                }
            }
        }
    },

    //非诉类型状态
    nonlawStatus(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.type_nonlawsuit).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //刑事类型状态
    penalStatus(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.type_penal).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //诉讼类型状态
    lawsuitStatus(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.configAll.type_lawsuit).value;
            for (let index in convertData) {
                if(value == convertData[index].name){
                    return convertData[index].value
                }
            }
        }
    },

    //案件状态
    caseStatus(value,type){
        let array = [];
        const store = useStore();
        if(type == 'type_nonlawsuit'){
            array = computed(() => store.state.configAll.type_nonlawsuit).value;
        }else if(type == 'type_penal'){
            array = computed(() => store.state.configAll.type_penal).value;
        }else if(type == 'type_lawsuit'){
            array = computed(() => store.state.configAll.type_lawsuit).value;
        }
        for(let key in array){
            if(value == array[key].name){
                return array[key].value
            }
        }
    },

    //开票状态
    invoiceStatus(value){
        const store = useStore();
        if(value){
            let convertData = computed(() => store.state.invoiceStatus).value;
            for (let index in convertData) {
                if(value == convertData[index].value){
                    return convertData[index].label
                }
            }
        }
    },

    //开庭状态
    confirmStatus(value){
        const store = useStore();        
        let convertData = computed(() => store.state.confirm_status).value;
        for(let key in convertData){
            if(value == convertData[key].value){
                return convertData[key].label
            }
        }
    },

    //到账状态
    collStatus(value){
        const store = useStore();        
        let convertData = computed(() => store.state.coll_status).value;
        for(let key in convertData){
            if(value == convertData[key].value){
                return convertData[key].label
            }
        }
    },

    //到账状态颜色
    collStatusColor(value){
        const store = useStore();
        let convertData = computed(() => store.state.coll_status).value;
        for(let key in convertData){
            if(value == convertData[key].value){
                return convertData[key].color
            }
        }
    },

    //开票状态
    invoiceStatus(value){
        const store = useStore();        
        let convertData = computed(() => store.state.invoice_status).value;
        for(let key in convertData){
            if(value == convertData[key].value){
                return convertData[key].label
            }
        }
    },

    //发票审批状态
    appStatus(value){
        const store = useStore();        
        let convertData = computed(() => store.state.approval_status).value;
        for(let key in convertData){
            if(value == convertData[key].value){
                return convertData[key].label
            }
        }
    }
}